module main

import dialog

// 弹出消息框 string num 0~2
@[export: 'message']
pub fn message(msg &char, num int) bool {
	match num {
		0 {
			return dialog.message(unsafe {msg.vstring()})
		}
		1 {
			return dialog.message(unsafe {msg.vstring()}, buttons: .ok_cancel)
		}
		else {
			return dialog.message(unsafe {msg.vstring()}, buttons: .yes_no)
		}
	}
}

// 弹出输入框
@[export: 'prompt']
pub fn prompt(str &char) string {
	d := dialog.prompt(unsafe {str.vstring()}) or { '' }
	return d
}

// 打开文件框
@[export: 'file_dialog']
pub fn file_dialog() string {
	f := dialog.file_dialog() or { '' }
	return f.str()
}

// 打开文件夹
@[export: 'open_dir']
pub fn open_dir(path &char) string {
	f := dialog.FileOpenOptions{unsafe {path.vstring()}}
	p, _ := dialog.open_dir(f) or { return '' }
	return p
}

// 保存文件
@[export: 'save_file']
pub fn save_file(content &char, path &char, filename &char) bool {
	f := dialog.FileSaveOptions{unsafe {path.vstring()}, unsafe {filename.vstring()}}
	dialog.save_file(unsafe {content.vstring()}, f) or { return false }
	return true
}


/* @[export: 'strdemo']
pub fn strdemo(strs voidptr) voidptr 
{
	return strs
} */

/* fn main() {
	f := file_dialog()
	println(f.str())
} */